package org.jeecg.common.system.base.entity;

import com.alibaba.fastjson.annotation.JSONField;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import lombok.experimental.Accessors;

import java.io.Serializable;
import java.util.Date;

/**
 * 通用 Entity
 *
 * @author chechen
 * @date 2022-02-14
 */
@Data
@Accessors(chain = true)
public class GenericEntity implements Serializable {
    private static final long serialVersionUID = 1L;

    @ApiModelProperty(value = "创建人", hidden = true)
    protected String createBy;

    @JSONField(format = "yyyy-MM-dd HH:mm:ss")
    @ApiModelProperty(value = "创建时间", hidden = true)
    protected Date createTime;

    @ApiModelProperty(value = "更新人", hidden = true)
    protected String updateBy;

    @JSONField(format = "yyyy-MM-dd HH:mm:ss")
    @ApiModelProperty(value = "更新时间", hidden = true)
    protected Date updateTime;

    /**
     * 清除数据
     */
    public void clearFields() {
        this.createBy = null;
        this.createTime = null;
        this.updateBy = null;
        this.updateTime = null;
    }

    /**
     * 同化
     */
    public <E extends GenericEntity> void assimilation(E entity) {
        this.createBy = entity.createBy;
        this.createTime = entity.createTime;
        this.updateBy = entity.updateBy;
        this.updateTime = entity.updateTime;
    }
}
